package Algorithm.LinkedListProblem;

/**
 * @Author cj
 * @Date 2021/11/18 19:34
 */
public class printCommonPart {

    class Node {
        public int value;
        public Node next;

        public Node(int val) {
            this.value = val;
        }
    }

    public static void printCommonPart1(Node head1, Node head2) {
        while (head1 != null && head2 != null) {
            if (head1.value == head2.value) {
                System.out.println(head1.value + " ");
                head1 = head1.next;
                head2 = head2.next;
            } else if (head1.value < head2.value) {
                head1 = head1.next;
            } else {
                head2 = head2.next;
            }
        }
    }
}
